<?php
//

/*
错误码

    302311	序列号错误
302312	序列号无效
302313	苹果服务器繁忙 不扣费，请重新提交
302315	已更换产品的序列号


关联数组
$json=array("sn"=>"C39PPPT5G5QY","model"=> "iPhone 6 Plus",.... );
等价
 $json["sn"] ="C39PPPT5G5QY" ;
 $json["production"]["start"]="2015-05-14";

 foreach($json as $x=>$x_value) {
  echo "Key=" . $x . ", Value=" . $x_value;
  echo "<br>";
}
*/

//http://data.3023.com/apple/gsx/
//双引号编译器解释，
//数字可用可不用引号,

//http://data.3023.com/apple/
include_once ("common.php");

function phoneImeiInfo($fromUsername,$toUsername,$keyword){
	$textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>0</FuncFlag>
                </xml>";                          //构造XML数据格式
	$msgType = "text";                         //定义响应消息类型text

	/*********业务逻辑开始*******/
    $url = "https://api.3023.com/apple/imei?imei=$keyword";
      //$url = "https://api.3023.com/apple/sn?sn=C39PPPT5G5QY";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("key:c07440ba148e7822b4a7a8c819d2d129"));

curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,15);
$response = curl_exec($ch);
curl_close($ch);
$jsonStr = json_decode($response,true);

       logWrite("$response=".$response) ;


       $contentStr =$response;// $jsonStr['code'];

       $responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);

    	echo $responseStr;
    	exit;

    	/*

    $contentStr="";			//结果字符串
     $contentStr =  $contentStr . "IMEI:" .$json["imei"]."\n" ;
    $contentStr =  $contentStr . "序列号:" .$json["sn"]."\n" ;
    $contentStr =  $contentStr . "型号:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "容量:" .$json["capacity"]."\n" ;
    $contentStr =  $contentStr . "颜色:" .$json["color"]."\n" ;
    $contentStr =  $contentStr . "版本:" .$json["number"]."\n" ;
    $contentStr =  $contentStr . "类型:" .$json["identifier"]."\n" ;
    $contentStr =  $contentStr . "模型(参考):" .$json["order"]."\n" ;
    $contentStr =  $contentStr . "网络:" .$json["network"]."\n" ;
    $contentStr =  $contentStr . "激活状态(参考):" .$json["activated"]."\n" ;
    $contentStr =  $contentStr . "产品类型:" .$json["product"]."\n" ;
    $contentStr =  $contentStr . "产地:" .$json["production"]["origin"]."\n" ;
    $contentStr =  $contentStr . "设备图片:" .$json["img"]."\n" ;



	$responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);
    	//把格式化的字符串写入变量
    	echo $responseStr;
    	*/
}





function phoneSnInfo($fromUsername,$toUsername,$keyword){
	$textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>0</FuncFlag>
                </xml>";                          //构造XML数据格式
	$msgType = "text";                         //定义响应消息类型text

	/*********业务逻辑开始*******/
$textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>0</FuncFlag>
                </xml>";                          //构造XML数据格式
	$msgType = "text";                         //定义响应消息类型text

	/*********业务逻辑开始*******/
    //$url = "https://api.3023.com/apple/sn?sn=$keyword";
     $url = "https://api.3023.com/apple/coverage?app=senior&sn=FCCRF00UGRX2";

     $url = "https://api.3023.com/apple/coverage?app=senior&sn=$keyword";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("key:c07440ba148e7822b4a7a8c819d2d129"));

curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,15);
$response = curl_exec($ch);
curl_close($ch);
$jsonStr = json_decode($response,true);

       logWrite("$response=".$response) ;


       $contentStr =$response;// $jsonStr['code'];

       $responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);

    	echo $responseStr;
    	exit;

/*
    $contentStr="";			//结果字符串
    $contentStr =  $contentStr . "序列号:" .$json["sn"]."\n" ;
    $contentStr =  $contentStr . "型号:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "容量:" .$json["capacity"]."\n" ;
    $contentStr =  $contentStr . "颜色:" .$json["color"]."\n" ;
    $contentStr =  $contentStr . "版本:" .$json["number"]."\n" ;
    $contentStr =  $contentStr . "类型:" .$json["identifier"]."\n" ;
    $contentStr =  $contentStr . "模型(参考):" .$json["order"]."\n" ;
    $contentStr =  $contentStr . "网络:" .$json["network"]."\n" ;
    $contentStr =  $contentStr . "激活状态(参考):" .$json["activated"]."\n" ;
    $contentStr =  $contentStr . "预估购买日期，即首次激活日期（参考）:" .$json["purchase"][date]."\n" ;
    $contentStr =  $contentStr . "保修结束日期（参考）:" .$json["coverage"]."\n" ;
    $contentStr =  $contentStr . "保修剩余（参考）:" .$json["daysleft"]."\n" ;
    $contentStr =  $contentStr . "技术支持结束日期（参考）:" .$json["support"]."\n" ;
     $contentStr =  $contentStr . "applecare :" .$json["applecare"]."\n" ;
      $contentStr =  $contentStr . "refurbished :" .$json["refurbished"]."\n" ;
    $contentStr =  $contentStr . "产品类型:" .$json["product"]."\n" ;
    $contentStr =  $contentStr . "出厂日期:" .$json["production"]["end"]."\n" ;
    $contentStr =  $contentStr . "产地:" .$json["production"]["origin"]."\n" ;
     $contentStr =  $contentStr . "翻新:"   .  $json["renovate"]."\n" ;
    //$contentStr =  $contentStr . "翻新机概率:"   .  $json["renovate"]["probability"]."\n" ;
    //$contentStr =  $contentStr . "鉴定结果:" . $json["renovate"]["result"]."\n" ;
    $contentStr =  $contentStr . "设备图片:" .$json["img"]."\n" ;

	$responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);
    	//把格式化的字符串写入变量
    	echo $responseStr;     //响应XML数据

    	*/
}



?>